const express = require('express');
const router = express.Router();

const sql=require('../db/index');


router.get('/privileges', async(req, res)=>{
  console.log(req.query);
  let {page,pageSize}=req.query;
  let start=(page-1)*pageSize;
  let [privileges] = await sql.query(`select * from base_privilege limit ${start},${pageSize}`);
  
  
  res.send({
    code : 200,
    message:"获取成功",
    data:privileges
  })


});

//更新
router.post('/privileges/deletes', async(req, res)=>{
  let {id,name,description,route,route_name,type,icon,hidden,num,parent_id}=req.body;
        let mysql='';route
        console.log(id,name,description,route,route_name,type,icon,hidden,num,parent_id)
      if(id)
        {
            mysql= `update base_privilege set name=${name},
            description=${description},route=${route},route_name=${route_name},type=${type},icon=${icon},hidden=${hidden},num=${num},parent_id=${parent_id} where id=${id}`
        }else{
            mysql=`insert into base_privilege (id,name,description,route,route_name,type,icon,hidden,num,parent_id) values
        id,${name},null${route},${route_name},${type},${icon},${hidden},${num},${parent_id})`
        }
            res.send({
            status: 200,
            message: '操作成功',
            data: null,
            timestamp: new Date().getTime()
            })
});


module.exports = router;
